<template >
  <div class="add_con_form tl" v-loading="loading">
    <el-dialog
      :close-on-click-modal="false"
      title="充值"
      :modal-append-to-body="false"
      :visible.sync="visible"
      :show="show"
      :before-close="closeDialog"
      @close="$emit('update:show',false)"
      class="tl size_13"
      width="800px"
    >
      <el-form :model="data" :rules="dataYZ" ref="data" class="mar_top" label-width="120px">
        <el-form-item label="用户名">
          <el-col :span="12">
            <el-input :placeholder="this.editUser" :disabled="true" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="充值类型" prop="recharge_type">
          <el-col :span="12">
            <el-select
              v-model="data.recharge_type"
              placeholder="请选择"
              @change="handChange"
              style="width:100%"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>

        <el-form-item label="充值金额" prop="num">
          <el-col :span="12">
            <el-input placeholder v-model="data.num" clearable></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="管理员备注" prop="remark">
          <el-col :span="12">
            <el-input
              type="textarea"
              placeholder
              v-model="data.remark"
              clearable
            ></el-input>
          </el-col>
        </el-form-item>
        
        <el-form-item>
          <el-button
            :loading="$store.state.isLoading"
            size="medium"
            type="primary"
            @click.prevent="addUpdate('data')"
          >确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>


<style lang="less" scoped></style>

<script>
export default {
  data() {
    return {
      options: [
        {
          value: "",
          label: ""
        }
      ],
      data: {
        id: "",
        recharge_type: "",
        num: "",
        remark: ""
      },
      loading: false,
      dataYZ: {
        //     title:[
        //     { validator: checkTitle, trigger: 'blur' }
        //     ],
      },
      visible: this.show
    };
  },
  props: {
    show: Boolean,
    editId: String,
    editUser: String,
    clickNum: Number
  },
  methods: {
    handChange(val) {
      console.log(val);
      this.data.rating = val;
    },
    getOptionList() {
      //this.options = [{value:'加余额',label:'加余额1'},{value:'减余额',label:'减余额'},{value:'加积分',label:'加积分'},{value:'减积分',label:'减积分'},{value:'加佣金',label:'加佣金'},{value:'减佣金',label:'减佣金'}];
      var data = {};
      this.$api.getUser.getRechargeOption(data).then(res => {
        this.options = res.data.result;
      });
    },
    closeDialog() {
      this.visible = false;
    },
    addUpdate(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          var params = {};
          params["id"] = this.data.id;
          params["recharge_type"] = this.data.recharge_type;
          params["num"] = this.data.num;
          params["remark"] = this.data.remark;
          this.$api.getUser.userRechargeSaveEdit(params).then(res => {
            if (res.data.code == 200 && res.data.result != null) {
              this.$emit("parent", "这里刷新父页面");
              this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
              this.visible = false;
            } else {
              this.$fnc.alertError(res.data.result); //失败弹出框
            }
          });
        }
      });
    }
  },
  watch: {
    show() {
      console.log(this.show);
      this.visible = this.show;
    },
    clickNum(id) {
      console.log("点击button次数", id);
      console.log("编辑ID=" + this.editId);
      //this.getDetails(this.editId);
      this.data.id = this.editId;
      console.log("会员名:", this.editUser);
    }
  },
  mounted() {
    this.getOptionList();
  },
  created() {}
};
</script>
